package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {


    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){

        return  wmNewsService.findAll(dto);
    }
    /**
     * {title: "震惊!块停下你饭后这三个行为!", type: "1", labels: "测试", publishTime: "2022-08-30T12:19:55.000Z",…}
     * channelId: 6
     * content: "[{\"type\":\"image\",\"value\":\"http://1.12.69.67:9000/wyq/2022/08/30/749a3fb3d1044937ab272d32f2b0f38a.jpg\"},{\"type\":\"text\",\"value\":\"早睡早起身体好\"},{\"type\":\"text\",\"value\":\"请在这里输入正文\"}]"
     * images: ["http://1.12.69.67:9000/wyq/2022/08/30/195ab0aa782f4442bb64baff2c984098.png"]
     * 0: "http://1.12.69.67:9000/wyq/2022/08/30/195ab0aa782f4442bb64baff2c984098.png"
     * labels: "测试"
     * publishTime: "2022-08-30T12:19:55.000Z"
     * status: 1
     * title: "震惊!块停下你饭后这三个行为!"
     * type: "1"
     */
    @PostMapping("submit")
    public ResponseResult addNews(@RequestBody WmNewsDto newsDto) throws Exception {

        ResponseResult result=wmNewsService.add(newsDto);
        return result;
    }

}